package com.yuexunit.operationman.nbsy.module.OperationRiskAssessment.ui;

import android.view.View;
import android.widget.TextView;


import com.yuexunit.operationman.nbsy.R;
import com.yuexunit.operationman.nbsy.base.BaseKJActivity;
import com.yuexunit.operationman.nbsy.config.AppConfig;
import com.yuexunit.operationman.nbsy.module.OperationRiskAssessment.bean.RiskAssessmentBean;

import org.kymjs.kjframe.utils.PreferenceHelper;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by chenss on 2017/8/9 0009.
 */

public class Act_RiskAssessmentPreview extends BaseKJActivity {

    @Bind(R.id.tv_patient_name)
    TextView tvPatientName;
    @Bind(R.id.tv_patient_sex)
    TextView tvPatientSex;
    @Bind(R.id.tv_patient_visitno)
    TextView tvPatientVisitno;
    @Bind(R.id.tv_patient_disease)
    TextView tvPatientDisease;
    @Bind(R.id.riskassessment_01)
    TextView riskassessment01;
    @Bind(R.id.riskassessment_02)
    TextView riskassessment02;
    @Bind(R.id.riskassessment_03)
    TextView riskassessment03;
    @Bind(R.id.riskassessment_04)
    TextView riskassessment04;
    @Bind(R.id.riskassessment_05)
    TextView riskassessment05;
    @Bind(R.id.riskassessment_06)
    TextView riskassessment06;
    @Bind(R.id.riskassessment_07)
    TextView riskassessment07;
    @Bind(R.id.riskassessment_08)
    TextView riskassessment08;
    @Bind(R.id.riskassessment_09)
    TextView riskassessment09;
    @Bind(R.id.riskassessment_10)
    TextView riskassessment10;
    @Bind(R.id.riskassessment_11)
    TextView riskassessment11;
    @Bind(R.id.riskassessment_12)
    TextView riskassessment12;

    @Override
    public void setRootView() {
        setContentView(R.layout.act_riskassessmentpreview);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        super.initData();
        setTitle();
        setContent();
    }

    private void setTitle() {
        tvPatientName.setText(AppConfig.RISKASSESSMENTBEAN.getObject().getRisk().getPatientName());
        if (AppConfig.RISKASSESSMENTBEAN.getObject().getRisk().getPatientSex().equals("1")) {
            tvPatientSex.setText("男");
        } else if (AppConfig.RISKASSESSMENTBEAN.getObject().getRisk().getPatientSex().equals("2")) {
            tvPatientSex.setText("女");
        } else {
            tvPatientSex.setText("不详");
        }
        tvPatientVisitno.setText("住院号" + AppConfig.RISKASSESSMENTBEAN.getObject().getRisk().getInHospitalNo());
        tvPatientDisease.setText(PreferenceHelper.readString(aty, AppConfig.PATIENT_INFO, AppConfig.PATIENT_DISEASE));
    }

    private void setContent() {
        for (RiskAssessmentBean.ObjectEntity.RiskItemListEntity p : AppConfig.RISKASSESSMENTBEAN.getObject().getRiskItemList()) {
            switch (p.getItemCode()) {
                case "QK_L":
                    if(p.getItemValue().length() > 0)
                    {
                        String[] array = p.getItemValue().split(";",-1);
                        String content = "";
                        String[] arrays = getResources().getStringArray(R.array.riskassessment_01);
                        if(array[0].equals("1"))
                        {
                            riskassessment01.setText(arrays[0]);
                        }
                        if(array[0].equals("2"))
                        {
                            riskassessment01.setText(arrays[1]);
                        }
                        if(array[0].equals("3"))
                        {
                            riskassessment01.setText(arrays[2]);
                        }
                        if(array[0].equals("4"))
                        {
                            riskassessment01.setText(arrays[3]);
                        }
                    }
                    break;
                case "MZ_P":
                    if(p.getItemValue().length() > 0)
                    {
                        String[] array = p.getItemValue().split(";",-1);
                        String content = "";
                        String[] arrays = getResources().getStringArray(R.array.riskassessment_02);
                        if(array[0].equals("1"))
                        {
                            riskassessment02.setText(arrays[0]);
                        }
                        if(array[0].equals("2"))
                        {
                            riskassessment02.setText(arrays[1]);
                        }
                        if(array[0].equals("3"))
                        {
                            riskassessment02.setText(arrays[2]);
                        }
                        if(array[0].equals("4"))
                        {
                            riskassessment02.setText(arrays[3]);
                        }
                        if(array[0].equals("5"))
                        {
                            riskassessment02.setText(arrays[4]);
                        }
                        if(array[0].equals("6"))
                        {
                            riskassessment02.setText(arrays[5]);
                        }
                    }
                    break;
                case "SJ_T":
                    if(p.getItemValue().length() > 0) {
                        String[] array = p.getItemValue().split(";",-1);
                        String content = "";
                        String[] arrays = getResources().getStringArray(R.array.riskassessment_03);
                        if (array[0].equals("1")) {
                            riskassessment03.setText(arrays[0]);
                        }
                        if (array[0].equals("2")) {
                            riskassessment03.setText(arrays[1]);
                        }
                    }
                    break;
                case "LB_K":
                    if(p.getItemValue().length() > 0) {
                        String[] array = p.getItemValue().split(";",-1);
                        String content = "";
                        String[] arrays = getResources().getStringArray(R.array.riskassessment_04);
                        if (array[0].equals("1")) {
                            riskassessment04.setText(arrays[0]);
                        }
                        if (array[0].equals("2")) {
                            riskassessment04.setText(arrays[1]);
                        }
                        if (array[0].equals("3")) {
                            riskassessment04.setText(arrays[2]);
                        }
                        if (array[0].equals("5")) {
                            riskassessment04.setText(arrays[3]);
                        }
                    }
                    break;
                case "LB_JZ":
                    if(p.getItemValue().length() > 0) {
                        String[] array = p.getItemValue().split(";",-1);
                        String content = riskassessment04.getText().toString();
                        String[] arrays = getResources().getStringArray(R.array.riskassessment_04);
                        if (array[0].equals("1")) {
                            riskassessment04.setText(content+"\n"+arrays[4]);
                        }
                    }
                    break;
                case "suiFang":
                    if(p.getItemValue().length() > 0) {
                        String[] array = p.getItemValue().split(";",-1);
                        String content = "";
                        String[] arrays = getResources().getStringArray(R.array.riskassessment_05);
                        if (array[0].equals("1")) {
                            riskassessment08.setText(arrays[0]);
                        }
                    }
                    break;
                case "qieKou":
                    if(p.getItemValue().length() > 0) {
                        String[] array = p.getItemValue().split(";",-1);
                        String content = "";
                        String[] arrays = getResources().getStringArray(R.array.riskassessment_05);
                        if (array[0].equals("1")) {
                            riskassessment09.setText(arrays[1]);
                        }
                        if (array[0].equals("2")) {
                            riskassessment09.setText(arrays[2]);
                        }
                    }
                    break;
            }
        }
        if (AppConfig.RISKASSESSMENTBEAN.getObject().getRisk().getRiskRank() != null) {
            riskassessment05.setText(AppConfig.RISKASSESSMENTBEAN.getObject().getRisk().getRiskRank()+"");
        }
        if (AppConfig.RISKASSESSMENTBEAN.getObject().getRisk().getRiskDoctor() != null) {
            riskassessment06.setText(AppConfig.RISKASSESSMENTBEAN.getObject().getRisk().getRiskDoctor());
        }
        if(AppConfig.RISKASSESSMENTBEAN.getObject().getRisk().getOperationSign() != null){
            riskassessment10.setText(AppConfig.RISKASSESSMENTBEAN.getObject().getRisk().getOperationSign());
        }
        if(AppConfig.RISKASSESSMENTBEAN.getObject().getRisk().getAnesthetistSign() != null){
            riskassessment11.setText(AppConfig.RISKASSESSMENTBEAN.getObject().getRisk().getAnesthetistSign());
        }
        if(AppConfig.RISKASSESSMENTBEAN.getObject().getRisk().getNursesSign() != null){
            riskassessment12.setText(AppConfig.RISKASSESSMENTBEAN.getObject().getRisk().getNursesSign());
        }
    }

    @OnClick({R.id.titlebar_docadvice_img_back, R.id.tv_submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.titlebar_docadvice_img_back:
                finish();
                break;
            case R.id.tv_submit:
                finish();
                break;
        }
    }
}
